<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>典型案例类型管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/frontEnd/images/favicon.ico">
    <link rel="stylesheet" href="/layuicms/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/layuicms/css/public.css" media="all" />
    <link rel="stylesheet" href="/kindeditor/themes/default/default.css" />
    <link rel="stylesheet" href="/kindeditor/plugins/code/prettify.css" />
    <script charset="utf-8" src="/kindeditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="/kindeditor/lang/zh-CN.js"></script>
    <script charset="utf-8" src="/layuicms/js/x-layui.js"></script>
    <script type="text/javascript" src="/layuicms/layui/layui.js"></script>
    <style type="text/css">
        .ke-container.ke-container-default{
            width: 100% !important;
        }
    </style>
</head>

<body>
<!-- 添加和修改的弹出层开始 -->
<div style="padding: 5px 20px 0 0" id="addOrUpdateDiv">
    <form action="" method="post" class="layui-form" id="dataFrm" lay-filter="dataFrm">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">警示类型</label>
                <div class="layui-input-inline">
                    <select name="safetyId" id="safetyId" disabled  class="search_safety"   lay-filter="safetyId">
                        <option value="0">请选择警示类型</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">文件夹</label>
                <div class="layui-input-inline">
                    <select name="coreId" id="coreId" class="search_fileType" lay-filter="fileType">
                        <option value="0">请选择文件夹</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">案例标题</label>
            <div class="layui-input-block">
                <input type="hidden" name="id" id="id">
                <input type="text" style="width: 515px" name="classicTitle" id="classicTitle" lay-verify="required" lay-reqtext="案例标题是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文件类型</label>
            <div class="layui-input-block">
                <input type="radio" name="fileType" lay-filter="fileType" value="1" title="PPT" checked="">
                <input type="radio" name="fileType" lay-filter="fileType" value="2" title="视频">
                <span class="layui-inline" style="color: red;margin-top: 10px;">* 请正确选择文件类型 .默认为PPT*</span>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-upload">
                <label class="layui-form-label">附件</label>
                <input type="hidden" name="caseImage" id="caseImage">
                <button type="button" class="layui-btn layui-btn-sm" id="caseFile"><i class="layui-icon"></i>    选择文件</button>
                <span class="layui-inline" style="color: gray" id="fileName"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">是否可用</label>
                <div class="layui-input-inline">
                    <input type="radio" name="available"  value="1" title="可用" checked="">
                    <input type="radio" name="available" value="0" title="不可用" >
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">排序码</label>
                <div class="layui-input-block">
                    <input type="text" id="ordernum" name="ordernum" lay-verify="required|number" autocomplete="off" placeholder="请输入排序码[>0]" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="doSubmit" id="doSubmit" ><span class="layui-icon layui-icon-add-1"></span>提交</button>
                <button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh-1"></span>重置</button>
            </div>
        </div>
    </form>
</div>
<!-- 添加和修改的弹出层结束 -->
</body>
<script type="text/javascript" src="/layuicms/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['upload','jquery','form','table','layer'],function(){
        var $ = layui.jquery;
        var form=layui.form;
        var layer = layui.layer,upload = layui.upload;
        //初始化添加和修改页面的下拉列表
        function initSafetySelect(safetyId){
            var dom = $("#safetyId");
            dom.html("");
            $.get("/safetyAlertType/loadAllsafetyAlertTypeForSelect",function(res){
                var data=res.data;
                var dom=$("#safetyId");
                var html='<option value="0">请选择供应商</option>'
                $.each(data,function(index,item){
                    html+='<option value="'+item.id+'">'+item.typename+'</option>'
                });
                dom.html(html);
                //如果safetyId有值就反选
                if (safetyId!=undefined){
                    dom.val(safetyId);
                }
                form.render("select");
            });
        }

        //加文件夹列表
        function initFileTypeSelect(safetyId,coreId) {
            $.get("/coreType/loadBySafetyTypeForSelect",{safetyId:safetyId},function(res){
                var data=res.data;
                var dom=$("#coreId");
                var html='<option value="0">请选择商品</option>'
                $.each(data,function(index,item){
                    html+='<option value="'+item.id+'">'+item.typename+'</option>'
                });
                dom.html(html);
                //如果coreId有值就反选
                if (coreId!=undefined){
                    dom.val(coreId);
                }
                form.render("select");
            });
        }
        //监听添加页面供应商下拉框的改变事件
        form.on('select(safetyId)',function (data) {
            var safetyId = data.value;
            initSafetySelect(safetyId);
        })
        upload.render({
             elem: '#caseFile'
            ,url: '/file/uploadFild'
            ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(0); //上传loading
            }
            ,accept: 'file'
            ,exts: 'ppt|pptx|mp4'
            ,field:'mf'
            ,done: function(res, index, upload){
                    var path = res.path;
                    var fileName = res.fileName;
                    $('.thumbImg').attr('src','/file/showImageByPath?path='+path);
                    $('.thumbBox').css("background","#fff");
                    $("#fileName").text(fileName);//给隐藏域赋值
                    $("#caseImage").val(path);//给隐藏域赋值
                    layer.closeAll('loading'); //关闭loading
                }
        });
        var id = $(window.parent.document).find("#editId").val();
        $.get("/caseClassic/loadCaseClassicById/"+id,function (res) {
            var data = res.data.item;
            $("input[name=available][value='1']").attr("checked", data.available == 1 ? true : false);
            $("input[name=available][value='0']").attr("checked", data.available == 0 ? true : false);
            $("input[name=fileType][value='1']").attr("checked", data.fileType == 1 ? true : false);
            $("input[name=fileType][value='2']").attr("checked", data.fileType == 2 ? true : false);
            form.render(); //更新全部
            //加载查询条件供应商的下拉列表
            $("#id").val(data.id);
            $("#classicTitle").val(data.classicTitle);
            $("#fileName").text(data.caseImage);
            $("#caseImage").val(data.caseImage);//给隐藏域赋值
            $("#ordernum").val(data.ordernum);
            initSafetySelect(data.safetyId);
            initFileTypeSelect(data.safetyId,data.coreId);
        });
        //添加和修改的提交
        $("#doSubmit").click(function () {
            //同步富文本和textarea里面的内容
            var data = $("#dataFrm").serialize();
            var caseImae= $("#caseImage").val();
            if(caseImae==""){
                layer.msg("请选择要上传的文件");
            }else {
                $.post("/caseClassic/updateCaseClassic",data,function (res) {
                    if(res.code==20000){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.location.reload();
                    }
                    layer.msg(res.message);
                    parent.layer.close(index);
                })
            }
        });
    });
</script>
</html>